package com.liting.uitest.controller;

import com.liting.uitest.entity.FileInfo;
import com.liting.uitest.model.*;
import com.liting.uitest.service.FileInfoService;
import com.liting.uitest.service.impl.ImageTestServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@RestController
@Slf4j
@Api(tags = "界面评价")
public class ImageTestController {
    @Autowired
    private ImageTestServiceImpl testService;
    @Autowired
    private FileInfoService fileInfoService;

    @GetMapping("/image/report")
    @ApiOperation("图片评测报告")
    public BaseRes<Map<String, Object>> imageTestReport(@RequestParam("id") Long id) {
        try {
            Map<String, Object> result = testService.imageTestReport(id);
            return new BaseRes<>(result);
        } catch (Exception ex) {
            log.error("imageTestReport error", ex);
            return new BaseRes<>(null, 1, "获取界面评测报告失败");
        }

    }

    @GetMapping("/image/entropy")
    @ApiOperation("图片信息熵")
    public BaseRes<BigDecimal> imageEntropy(@RequestParam("id") Long id) {
        try {
            BigDecimal result = testService.imageEntropy(id);
            return new BaseRes<>(result);
        } catch (Exception ex) {
            log.error("imageEntropy error", ex);
            return new BaseRes<>(null, 1, "获取界面信息熵失败");
        }

    }

    @GetMapping("/image/colordistance")
    @ApiOperation("图片整体色差")
    public BaseRes<BigDecimal> imageColorDistance(@RequestParam("id") Long id) {
        try {
            BigDecimal result = testService.imageColorDistance(id);
            return new BaseRes<>(result);
        } catch (Exception ex) {
            log.error("imageColorDistance error", ex);
            return new BaseRes<>(null, 1, "获取界面色差失败");
        }

    }

    @PostMapping("/image/part/colordistance")
    @ApiOperation("图片框选后各部分的色差,框选部分的name必须有，返回的key为框选元素的name")
    public BaseRes<Map<String, BigDecimal>> imagePartColorDistance(
            @RequestBody ImageModule imageModule) {
        try {
            Map<String, BigDecimal> result = testService.imagePartColorDistance(imageModule.getId(), imageModule.getRectList(), imageModule.getCirList());
            return new BaseRes<>(result);
        } catch (Exception ex) {
            log.error("imagePartColorDistance error", ex);
            return new BaseRes<>(null, 1, "获取界面框选元素色差失败");
        }

    }


    @PostMapping("/image/whitespace")
    @ApiOperation("图片留白率")
    public BaseRes<BigDecimal> imageWhiteSpace(
            @RequestBody ImageModule imageModule) {
        try {
            BigDecimal result = testService.imageWhiteSpace(imageModule.getId(), imageModule.getRectList(), imageModule.getCirList());
            return new BaseRes<>(result);
        } catch (Exception ex) {
            log.error("imageWhiteSpace error", ex);
            return new BaseRes<>(null, 1, "获取界面留白率失败");
        }

    }

    @PostMapping("/image/vscalc")
    @ApiOperation("垂直对称性计算")
    public BaseRes<BigDecimal> vsCalc(
            @RequestBody ImageModule imageModule) {
        try {
            BigDecimal result = testService.vsCalc(imageModule.getId(), imageModule.getRectList(), imageModule.getCirList());
            return new BaseRes<>(result);
        } catch (Exception ex) {
            log.error("vsCalc error", ex);
            return new BaseRes<>(null, 1, "垂直对称性计算失败");
        }

    }

    @PostMapping("/image/balance")
    @ApiOperation("平衡感计算")
    public BaseRes<BigDecimal> baCalc(
            @RequestBody ImageModule imageModule) {
        try {
            BigDecimal result = testService.baCalc(imageModule.getId(), imageModule.getRectList(), imageModule.getCirList());
            return new BaseRes<>(result);
        } catch (Exception ex) {
            log.error("baCalc error", ex);
            return new BaseRes<>(null, 1, "平衡感计算失败");
        }

    }

    @PostMapping("/image/proportion")
    @ApiOperation("比例感计算")
    public BaseRes<BigDecimal> proportionCalc(
            @RequestBody ImageModule imageModule) {
        try {
            BigDecimal result = testService.proportionCalc(imageModule.getId(), imageModule.getRectList(), imageModule.getCirList());
            return new BaseRes<>(result);
        } catch (Exception ex) {
            log.error("proportionCalc error", ex);
            return new BaseRes<>(null, 1, "比例感计算失败");
        }

    }

    @PostMapping("/image/uncalc")
    @ApiOperation("整体感计算")
    public BaseRes<BigDecimal> unCalc(
            @RequestBody ImageModule imageModule) {
        try {
            BigDecimal result = testService.unCalc(imageModule.getId(), imageModule.getRectList(), imageModule.getCirList());
            return new BaseRes<>(result);
        } catch (Exception ex) {
            log.error("proportionCalc error", ex);
            return new BaseRes<>(null, 1, "整体感计算失败");
        }

    }

    @PostMapping("/image/simple")
    @ApiOperation("简单感计算")
    public BaseRes<BigDecimal> siCalc(
            @RequestBody ImageModule imageModule) {
        try {
            BigDecimal result = testService.siCalc(imageModule.getId(), imageModule.getRectList(), imageModule.getCirList());
            return new BaseRes<>(result);
        } catch (Exception ex) {
            log.error("proportionCalc error", ex);
            return new BaseRes<>(null, 1, "简单感计算失败");
        }

    }

    @PostMapping("/image/vision")
    @ApiOperation("视觉强度计算")
    public BaseRes<BigDecimal> visionCalc(
            @RequestBody VisionModule visionModule) {
        try {
            BigDecimal result = testService.visionCalc(visionModule);
            return new BaseRes<>(result);
        } catch (Exception ex) {
            log.error("visionCalc error", ex);
            return new BaseRes<>(null, 1, "视觉强度计算失败");
        }

    }


}
